package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetDepartMapper;
import com.lhys.pojo.AssetDepart;
import com.lhys.service.AssetDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 资产_部门表 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Service
public class AssetDepartServiceImpl implements AssetDepartService {
    @Autowired
    private AssetDepartMapper departMapper;


    @Override
    @Transactional
    public Boolean saveAssetDepart(AssetDepart assetDepart) {
        try {
            if (assetDepart.getId() == null) {
                assetDepart.setCreateTime(new Date());
                return departMapper.addAssetDepart(assetDepart) > 0;
            }
            return departMapper.updateAssetDepart(assetDepart) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetDepartById(Integer id) {
        return departMapper.delAssetDepart(id) > 0;
    }

    @Override
    public AssetDepart getAssetDepartById(Integer id) {
        return departMapper.getAssetDepartById(id);
    }

    @Override
    public PageInfo<AssetDepart> getAssetDepartList(AssetDepart assetDepart, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetDepart> list = departMapper.getAssetDepartByCodeAndTitleOrRemarkList(assetDepart);
        PageInfo<AssetDepart> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public AssetDepart getAssetDepartByCode(String code) {

        return departMapper.getAssetDepartByCode(code);
    }

    @Override
    public AssetDepart getAssetDepartByName(String title) {
        return departMapper.getAssetDepartByTitle(title);
    }


}
